package com.cai.servlet.common.topic;

import com.cai.dao.DetailedTopicDao;
import com.cai.dao.impl.DetailedTopicDaoImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author RuoLi
 * 搜索相匹配的题目
 */
@WebServlet(name = "ServletInputSearch", value = "/common/InputSearch")
public class ServletInputSearch extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        DetailedTopicDao dao = new DetailedTopicDaoImpl();
        String detailedTopicId = req.getParameter("detailedTopicId");
        String valueChapterName = req.getParameter("valueChapterName");
        String valueKnowledgePoint = req.getParameter("valueKnowledgePoint");
        if (detailedTopicId.length() != 0) {
            String data = dao.getTopicFromDetailedTopicId(Integer.parseInt(detailedTopicId));
            resp.getWriter().write(data);
        } else {
            if (valueChapterName.length() != 0 && valueKnowledgePoint.length() != 0) {

            } else if (valueKnowledgePoint.length() != 0) {

            } else if (valueChapterName.length() != 0) {

            }
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doPost(req, resp);
    }
}
